﻿using System;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;

namespace AisinGioro.Server.Hubs
{
    using Core;
    using Notify;

    /// <summary>
    /// 主动发送给客户端封装类，单例模式
    /// </summary>
    public class MsgHubCaller
    {
        /// <summary>
        /// Clients, 用来主动发送消息
        /// </summary>
        public IHubConnectionContext<dynamic> Clients { get; private set; }
        /// <summary>
        /// Groups, 用来操作群组
        /// </summary>
        public IGroupManager Groups { get; private set; }

        private readonly static MsgHubCaller _instance = new MsgHubCaller(GlobalHost.ConnectionManager.GetHubContext<MsgHub>().Clients, GlobalHost.ConnectionManager.GetHubContext<MsgHub>().Groups);
        private INotify _notify;

        public static MsgHubCaller Instance
        {
            get
            {
                return _instance;
            }
        }

        private MsgHubCaller(IHubConnectionContext<dynamic> clients, IGroupManager groups)
        {
            Clients = clients;
            Groups = groups;
            _notify = NotifyBase.GetInstance();
        }
        
        private WorkItemFamily _agentAliveFamily = new WorkItemFamily();
        private WorkItemFamily _monitorFamily = new WorkItemFamily();
        /// <summary>
        /// 当前所有在线的代理客户端
        /// </summary>
        public WorkItemFamily AliveAgentFamily
        {
            get { return _agentAliveFamily; }
        }
        /// <summary>
        /// 当前所有在线的检测项
        /// </summary>
        public WorkItemFamily MonitorFamily
        {
            get { return _monitorFamily; }
        }
    }
}
